package com.iot.fire.service.impl;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iot.fire.common.enums.DeviceStatus;
import com.iot.fire.domain.TDevice;
import com.iot.fire.mapper.TDeviceMapper;
import com.iot.fire.service.ITDeviceService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 设备信息Service业务层处理
 *
 * @author ruoyi
 * @date 2025-11-05
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class TDeviceServiceImpl extends ServiceImpl<TDeviceMapper, TDevice> implements ITDeviceService {

    /**
     * 获取设备列表
     *
     * @param deviceStatus 设备状态
     * @return 结果
     */
    @Override
    public List<TDevice> enableDeviceList(DeviceStatus deviceStatus) {
        LambdaQueryWrapper<TDevice> wrapper = Wrappers.lambdaQuery(TDevice.class);
        wrapper.eq(TDevice::getDeviceStatus, deviceStatus.getCode());
        return list(wrapper);
    }

    /**
     * 根据设备sn获取设备信息
     *
     * @param deviceSn 设备sn
     * @return 设备信息
     */
    @Override
    public TDevice getDeviceByDeviceSn(String deviceSn) {
        LambdaQueryWrapper<TDevice> wrapper = Wrappers.lambdaQuery(TDevice.class);
        wrapper.eq(TDevice::getDeviceCode, deviceSn).last("limit 1");
        return getOne(wrapper);
    }

}
